import type { CustomUploadFile } from './type'
import request from '@/utils/request'

enum API {
  UPLOAD = '/attachment/upload',
  GET_FILE = '/attachment/getByTable',
  DELETE = '/attachment/delete',
}

export function upload(formData: FormData) {
  return request<string>({
    url: API.UPLOAD,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
}

export function getByTable(table: string, tableId: number) {
  return request<CustomUploadFile[]>({
    url: `${API.GET_FILE}/${table}/${tableId}`,
    method: 'get',
  })
}

export function deleteFile(id: number) {
  return request<CustomUploadFile[]>({
    url: `${API.DELETE}/${id}`,
    method: 'post',
  })
}
